$(function(){
	
	abortionAnalysistSet={
			chart: {
				renderTo: 'container', 
	            type: 'line'                         
	        },
	        title: {
	            text: '每月人流曲线'     
	        },
	        xAxis: {
	            categories: []   
	        },
	        yAxis: {
	            title: {
	                text: '人数'                  
	            }
	        },
	        series: [{                                 
	            name: '人流人数',                          
	            data: []                        
	        },{
	        	 name: '一个月随访',                          
		         data: []   
	        },{
	        	 name: '三个月随访',                          
		         data: []   
	        },{
	        	 name: '六个月随访',                          
		         data: []   
	        }]
	};
	
	abortionReasonF2Set={
	        chart: {
	        	renderTo: 'countAbortionReasonF2', 
	        	type: 'pie',
	            plotShadow: false
	        },
	        title: {
	            text: '人工流产原因'
	        },
	        tooltip: {
	            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
	        },
	        plotOptions: {
	            pie: {
	                allowPointSelect: true,
	                cursor: 'pointer',
	                dataLabels: {
	                    enabled: false
	                },
	                showInLegend: true
	            }
	        },
	        series: [{
	            name: '占比',
	            data: []
	        }]
	    };
	
	abortionFailReasonF2={
	        chart: {
	        	renderTo: 'countAbortionFailReasonF2', 
	        	type: 'pie',
	            plotShadow: false
	        },
	        title: {
	            text: '避孕失败原因'
	        },
	        tooltip: {
	            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
	        },
	        plotOptions: {
	            pie: {
	                allowPointSelect: true,
	                cursor: 'pointer',
	                dataLabels: {
	                    enabled: false
	                },
	                showInLegend: true
	            }
	        },
	        series: [{
	            name: '占比',
	            data: []
	        }]
	    };
	
	//避孕方式（一个月随访）
	abortionOneMonthF2={
	        chart: {
	        	renderTo: 'countAbortionOneMonthF2', 
	        	type: 'pie',
	            plotShadow: false
	        },
	        title: {
	            text: '术后避孕方式（一个月随访）'
	        },
	        tooltip: {
	            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
	        },
	        plotOptions: {
	            pie: {
	                allowPointSelect: true,
	                cursor: 'pointer',
	                dataLabels: {
	                    enabled: false
	                },
	                showInLegend: true
	            }
	        },
	        series: [{
	            name: '占比',
	            data: []
	        }]
	    };
	
	//避孕方式（三个月随访）
	abortionThreeMonthF2={
	        chart: {
	        	renderTo: 'countAbortionThreeMonthF2', 
	        	type: 'pie',
	            plotShadow: false
	        },
	        title: {
	            text: '术后避孕方式（三个月随访）'
	        },
	        tooltip: {
	            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
	        },
	        plotOptions: {
	            pie: {
	                allowPointSelect: true,
	                cursor: 'pointer',
	                dataLabels: {
	                    enabled: false
	                },
	                showInLegend: true
	            }
	        },
	        series: [{
	            name: '占比',
	            data: []
	        }]
	    };
	
	//避孕方式（六个月随访）
	abortionSixMonthF2={
	        chart: {
	        	renderTo: 'countAbortionSixMonthF2', 
	        	type: 'pie',
	            plotShadow: false
	        },
	        title: {
	            text: '术后避孕方式（六个月随访）'
	        },
	        tooltip: {
	            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
	        },
	        plotOptions: {
	            pie: {
	                allowPointSelect: true,
	                cursor: 'pointer',
	                dataLabels: {
	                    enabled: false
	                },
	                showInLegend: true
	            }
	        },
	        series: [{
	            name: '占比',
	            data: []
	        }]
	    };
	
	searchAbortion();
	
  
	
});

/**
 * 条件查询
 */
function searchAbortion()
{

	var dateStart=$("#dateStart").datebox("getValue");
	var dateEnd=$("#dateEnd").datebox("getValue");
	 
	//每月人流数
	 $.ajax({
			url: "../analysis/abortion/month/count",
			data:{
				dateStart:dateStart,
				dateEnd:dateEnd
			},
			success: function(data){
				 var i,len=data.length;
			     var listUserNum=new Array();
			     for( i=0;i<len;i++){
		       	  var userNumObj=data[i];
		       	  listUserNum.push(userNumObj.num);
		       	  abortionAnalysistSet.xAxis.categories[i]=userNumObj.anMonth;
		         }   
		         abortionAnalysistSet.series[0].data = listUserNum;
		         abortionAnalysistChart=new Highcharts.Chart(abortionAnalysistSet);
		         
		         //一个月随访
		         followMonthData(dateStart,dateEnd,'51',1);
		         
		         //三个月随访
		         followMonthData(dateStart,dateEnd,'52',2);
		         
		         //六个月随访
		         followMonthData(dateStart,dateEnd,'53',3);
		         
		         //人流总数
		         abortionTotalNum(dateStart,dateEnd);
		         
		         //一个月随访总数
		         abortionMonthNum(dateStart,dateEnd,'51');
		         
		         //三个月随访总数
		         abortionMonthNum(dateStart,dateEnd,'52');
		         
		         //六个月随访总数
		         abortionMonthNum(dateStart,dateEnd,'53');
			}
		});
	 
	 //怀孕原因
	 $.ajax({
			url: "../analysis/abortion/reason/count",
			data:{
				dateStart:dateStart,
				dateEnd:dateEnd,
				questionnaireId:'48',
				questionId:'54'
			},
			success: function(data){
				 var i,len=data.length;
			     var listReasonNum=new Array();
			     for( i=0;i<len;i++){
		       	  var reasonNumObj=data[i];
		       	  listReasonNum.push([reasonNumObj.description,reasonNumObj.num]);
		         }   
			     abortionReasonF2Set.series[0].data = listReasonNum;
		         new Highcharts.Chart(abortionReasonF2Set);
			}
		});
	 
	 //避孕失败原因
	 $.ajax({
			url: "../analysis/abortion/reason/count",
			data:{
				dateStart:dateStart,
				dateEnd:dateEnd,
				questionnaireId:'48',
				questionId:'55'
			},
			success: function(data){
				 var i,len=data.length;
			     var listReasonNum=new Array();
			     for( i=0;i<len;i++){
		       	  var reasonNumObj=data[i];
		       	  listReasonNum.push([reasonNumObj.description,reasonNumObj.num]);
		         }   
			     abortionFailReasonF2.series[0].data = listReasonNum;
		         new Highcharts.Chart(abortionFailReasonF2);
			}
		});
	 
	 //避孕方式【一个月随访】
	 $.ajax({
			url: "../analysis/abortion/reason/count",
			data:{
				dateStart:dateStart,
				dateEnd:dateEnd,
				questionnaireId:'51',
				questionId:'98'
			},
			success: function(data){
				 var i,len=data.length;
			     var listReasonNum=new Array();
			     for( i=0;i<len;i++){
		       	  var reasonNumObj=data[i];
		       	  listReasonNum.push([reasonNumObj.description,reasonNumObj.num]);
		         }   
			     abortionOneMonthF2.series[0].data = listReasonNum;
		         new Highcharts.Chart(abortionOneMonthF2);
			}
		});
	 
	 //避孕方式【三个月随访】
	 $.ajax({
			url: "../analysis/abortion/reason/count",
			data:{
				dateStart:dateStart,
				dateEnd:dateEnd,
				questionnaireId:'52',
				questionId:'98'
			},
			success: function(data){
				 var i,len=data.length;
			     var listReasonNum=new Array();
			     for( i=0;i<len;i++){
		       	  var reasonNumObj=data[i];
		       	  listReasonNum.push([reasonNumObj.description,reasonNumObj.num]);
		         }   
			     abortionThreeMonthF2.series[0].data = listReasonNum;
		         new Highcharts.Chart(abortionThreeMonthF2);
			}
		});
	 
	//避孕方式【六个月随访】
	 $.ajax({
			url: "../analysis/abortion/reason/count",
			data:{
				dateStart:dateStart,
				dateEnd:dateEnd,
				questionnaireId:'53',
				questionId:'147'
			},
			success: function(data){
				 var i,len=data.length;
			     var listReasonNum=new Array();
			     for( i=0;i<len;i++){
		       	  var reasonNumObj=data[i];
		       	  listReasonNum.push([reasonNumObj.description,reasonNumObj.num]);
		         }   
			     abortionSixMonthF2.series[0].data = listReasonNum;
		         new Highcharts.Chart(abortionSixMonthF2);
			}
		});
	 
}

//统计随访
function followMonthData(dateStart,dateEnd,questionnaireId,followNum)
{
	$.ajax({
		url: "../analysis/follow/month/count",
		data:{
			dateStart:dateStart,
			dateEnd:dateEnd,
			questionnaireId:questionnaireId
		},
		success: function(data){
			 var i,len=data.length;
		     var listNum=new Array();
		     for( i=0;i<len;i++){
	       	  var numObj=data[i];
	       	  listNum.push(numObj.num);
	         }
	         abortionAnalysistChart.series[followNum].setData(listNum);
		}
	});
}

//统计人流总数
function abortionTotalNum(dateStart,dateEnd)
{
	$.ajax({
		url: "../analysis/abortion/total/num",
		data:{
			dateStart:dateStart,
			dateEnd:dateEnd
		},
		success: function(data){
			 $("#abortionTotalNum").text(data);
		}
	});
}

//每月成功随访
function abortionMonthNum(dateStart,dateEnd,questionnaireId)
{
	$.ajax({
		url: "../analysis/abortion/month/num",
		data:{
			dateStart:dateStart,
			dateEnd:dateEnd,
			questionnaireId:questionnaireId
		},
		success: function(data){
			 $("#abortionMonthNum"+questionnaireId).text(data);
		}
	});
}
